Skip to content

Instantly share code, notes, and snippets.

@NeatWolf
Created June 30, 2019 08:06
Show Gist options
  • Save NeatWolf/4ae390fb896450dc58314da8361780c1 to your computer and use it in GitHub Desktop.
Save NeatWolf/4ae390fb896450dc58314da8361780c1 to your computer and use it in GitHub Desktop.
Puzzle Creator to Adventure Creation action trigger integration attempt
/*
*
* Adventure Creator
* by Chris Burton, 2013-2019
*
* "ActionTemplate.cs"
*
* This is a blank action template.
*
*/
/*
*
* Adventure Creator
* by Chris Burton, 2013-2019
*
* "ActionCheckMultipleTemplate.cs"
*
* This is a blank action template, which has any number of outputs.
*
*/
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace AC
{
[System.Serializable]
public class ActionPuzzleRun : ActionCheckMultiple
{
public int constantID = 0;
public int parameterID = -1;
// Declare variables here
public GameObject linkedObject;
protected GameObject runtimeLinkedObject;
public AP_PuzzleDetector_Pc cachedDetector;
public ActionPuzzleRun ()
{
this.isDisplayed = true;
category = ActionCategory.Custom;
title = "Puzzle Run";
description = "Runs a PuzzleCreator Puzzle.";
// Set the number of output sockets here if dynamic, or in the constructor if fixed
numSockets = 2;
}
override public float Run ()
{
/*
* This function is called when the action is performed.
*
* The float to return is the time that the game
* should wait before moving on to the next action.
* Return 0f to make the action instantenous.
*
* For actions that take longer than one frame,
* you can return "defaultPauseTime" to make the game
* re-run this function a short time later. You can
* use the isRunning boolean to check if the action is
* being run for the first time, eg:
*/
// First run
if (!isRunning)
{
isRunning = true;
if (!cachedDetector)
cachedDetector = GetDetector(runtimeLinkedObject);
// fail! No detector, insta exit
if (!cachedDetector)
{
isRunning = false;
return 0f;
}
// if we're here, we should be fine and with a valid cachedDetector
// Let's run it
if (!cachedDetector.b_PuzzleIsSolved)
cachedDetector.PC_Start_A_Puzzle();
}
else if (cachedDetector.b_PuzzleIsSolved)
{
isRunning = false;
return defaultPauseTime;
}
return defaultPauseTime;
/*
else
{
isRunning = false;
return 0f;
}*/
}
protected virtual AP_PuzzleDetector_Pc GetDetector(GameObject go)
{
return go.GetComponentInChildren<AP_PuzzleDetector_Pc>();
}
override public void Skip ()
{
/*
* This function is called when the Action is skipped, as a
* result of the player invoking the "EndCutscene" input.
*
* It should perform the instructions of the Action instantly -
* regardless of whether or not the Action itself has been run
* normally yet. If this method is left blank, then skipping
* the Action will have no effect. If this method is removed,
* or if the Run() method call is left below, then skipping the
* Action will cause it to run itself as normal.
*/
Run ();
}
override public void AssignValues (List<ActionParameter> parameters)
{
runtimeLinkedObject = AssignFile (parameters, parameterID, constantID, linkedObject);
if (!cachedDetector)
{
cachedDetector = GetDetector(runtimeLinkedObject);
}
/*customMessage = AssignString (parameters, customMessageParameterID, customMessage);
customValue = AssignInteger (parameters, customValueParameterID, customValue);*/
}
override public ActionEnd End (List<Action> actions)
{
/*// If the linkedObject is an immediately-starting ActionList, don't end the cutscene
if (runtimeLinkedObject && messageToSend == MessageToSend.Interact)
{
Cutscene tempAction = runtimeLinkedObject.GetComponent<Cutscene>();
if (tempAction != null && tempAction.triggerTime <= 0f)
{
ActionEnd actionEnd = new ActionEnd ();
actionEnd.resultAction = ResultAction.RunCutscene;
return actionEnd;
}
}*/
// Here, we decide which output socket to follow (starting from 0)
int outputSocketIndex = 1;
// 0 = success 1 fail
if (cachedDetector)
outputSocketIndex = cachedDetector.b_PuzzleIsSolved ? 0 : 1;
/*else
{
return (base.End (actions));
}*/
// Then, we pass this index number onto ProcessResult and return the result
return ProcessResult (outputSocketIndex, actions);
}
#if UNITY_EDITOR
override public void ShowGUI (List<ActionParameter> parameters)
{
// Action-specific Inspector GUI code here.
// Set the number of output sockets here if dynamic, or in the constructor if fixed
//numSockets = 2;
parameterID = Action.ChooseParameterGUI ("Object to affect:", parameters, parameterID, ParameterType.GameObject);
if (parameterID >= 0)
{
constantID = 0;
linkedObject = null;
}
else
{
linkedObject = (GameObject) EditorGUILayout.ObjectField ("Object to affect:", linkedObject, typeof(GameObject), true);
constantID = FieldToID (linkedObject, constantID);
linkedObject = IDToField (linkedObject, constantID, false);
}
}
override public void AssignConstantIDs (bool saveScriptsToo, bool fromAssetFile)
{
AssignConstantID (linkedObject, constantID, parameterID);
}
public override string SetLabel ()
{
// (Optional) Return a string used to describe the specific action's job.
if (linkedObject != null)
{
string labelAdd = string.Empty;
/*if (messageToSend == MessageToSend.TurnOn)
{
labelAdd = "'Turn on' ";
}
else if (messageToSend == MessageToSend.TurnOff)
{
labelAdd = "'Turn off' ";
}
else if (messageToSend == MessageToSend.Interact)
{
labelAdd = "'Interact' ";
}
else if (messageToSend == MessageToSend.Kill)
{
labelAdd = "'Kill' ";
}
else
{
labelAdd = "'" + customMessage + "' ";
}*/
labelAdd += ": " + linkedObject.name;
return labelAdd;
}
return string.Empty;
//return string.Empty;
}
protected override string GetSocketLabel (int i)
{
// (Optional) Return an output socket's label, given the index number (starting from 0).
//return ("If result is " + i.ToString () + ":");
switch (i)
{
case 1:
return "Puzzle Solved:";
default:
return "Puzzle Unsolved:";
}
//return "Option " + i.ToString () + ":";
}
#endif
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment