// PUBLIC STATIC METHODS: ----------------------------------------------------------------- public static bool CanSaveType(Variable.DataType dataType) { switch (dataType) { case Variable.DataType.Null: return(false); case Variable.DataType.String: return(true); case Variable.DataType.Number: return(true); case Variable.DataType.Bool: return(true); case Variable.DataType.Color: return(true); case Variable.DataType.Vector2: return(true); case Variable.DataType.Vector3: return(true); case Variable.DataType.Texture2D: return(true); case Variable.DataType.Sprite: return(true); case Variable.DataType.GameObject: return(false); } return(false); }
// OVERRIDERS: ---------------------------------------------------------------------------- protected override GUIContent[] GetVariables(int allowTypesMask) { if (this.target == null) { return(new GUIContent[0]); } LocalVariables[] localVariables = LocalVariablesUtilities.GatherLocals( this.target, this.inChildren ); List <GUIContent> variables = new List <GUIContent>(); for (int i = 0; i < localVariables.Length; ++i) { LocalVariables local = localVariables[i]; for (int j = 0; j < local.references.Length; ++j) { Variable.DataType type = (Variable.DataType)local.references[j].variable.type; if ((allowTypesMask & 1 << (int)type) == 0) { continue; } variables.Add(new GUIContent( " " + local.references[j].variable.name, VariableEditorUtils.GetIcon(type) )); } } return(variables.ToArray()); }
// PUBLIC METHODS: ------------------------------------------------------------------------ public static Texture2D GetIcon(Variable.DataType type) { string name = VARIABLE_ICON_NAMES[(int)type]; if (VARIABLE_ICONS == null) { VARIABLE_ICONS = new Dictionary <string, Texture2D>(); } if (!VARIABLE_ICONS.ContainsKey(name)) { Texture2D icon = AssetDatabase.LoadAssetAtPath <Texture2D>( Path.Combine(VARIABLE_ICONS_PATH, name) ); if (icon == null) { icon = AssetDatabase.LoadAssetAtPath <Texture2D>( Path.Combine(VARIABLE_ICONS_PATH, VARIABLE_ICON_DEFAULT_NAME) ); } VARIABLE_ICONS.Add(name, icon); } return(VARIABLE_ICONS[name]); }
// OVERRIDERS: ---------------------------------------------------------------------------- protected override GUIContent[] GetVariables(int allowTypesMask) { DatabaseVariables database = DatabaseVariables.Load(); if (database == null || database.GetGlobalVariables() == null) { PreferencesWindow.OpenWindowTab("Variables"); return(new GUIContent[0]); } GlobalVariables globalVariables = database.GetGlobalVariables(); List <GUIContent> variables = new List <GUIContent>(); for (int i = 0; i < globalVariables.references.Length; ++i) { Variable.DataType type = (Variable.DataType)globalVariables.references[i].variable.type; if ((allowTypesMask & 1 << (int)type) == 0) { continue; } variables.Add(new GUIContent( " " + globalVariables.references[i].variable.name, VariableEditorUtils.GetIcon(type) )); } return(variables.ToArray()); }
private void Initialize() { if (initialized) { return; } initialized = true; //if (photonView.IsMine || photonView.IsSceneView) { for (int i = 0, imax = localVars.Count; i < imax; i++) { int index = i; VarRPC rpc = localVars[i]; if (rpc == null || !rpc.variables) { continue; } for (int e = 0, emax = rpc.variables.references.Length; e < emax; e++) { var variable = rpc.variables.references[e]; Variable.DataType varType = (Variable.DataType)variable.variable.type; if (varType == Variable.DataType.Null || varType == Variable.DataType.GameObject || varType == Variable.DataType.Sprite || varType == Variable.DataType.Texture2D) { continue; } if (!VARS.ContainsKey(variable.variable.name)) { VARS.Add(variable.variable.name, variable); VariablesManager.events.SetOnChangeLocal( this.OnVariableChange, variable.gameObject, variable.variable.name ); } } } //Debug.LogWarningFormat("[LocalVarsNetwork] Initialized vars: {0}", VARS.Count); } }
protected void SyncValueWithVariable(string variableName) { object current = this.variable.Get(gameObject); if (current != null) { Variable.DataType dataType = this.variable.GetVariableDataType(gameObject); switch (dataType) { case Variable.DataType.Vector2: Vector2 newValue2 = (Vector2)current; if (this.component == Axis.X) { this.value = newValue2.x; } if (this.component == Axis.Y) { this.value = newValue2.y; } break; case Variable.DataType.Vector3: Vector3 newValue3 = (Vector3)current; if (this.component == Axis.X) { this.value = newValue3.x; } if (this.component == Axis.Y) { this.value = newValue3.y; } if (this.component == Axis.Z) { this.value = newValue3.z; } break; } } }
protected void SyncVariableWithValue(float newValue) { Variable.DataType dataType = this.variable.GetVariableDataType(gameObject); switch (dataType) { case Variable.DataType.Vector2: Vector2 vec2 = (Vector2)this.variable.Get(gameObject); if (this.component == Axis.X) { vec2.x = newValue; } if (this.component == Axis.Y) { vec2.y = newValue; } this.variable.Set(vec2, gameObject); break; case Variable.DataType.Vector3: Vector3 vec3 = (Vector3)this.variable.Get(gameObject); if (this.component == Axis.X) { vec3.x = newValue; } if (this.component == Axis.Y) { vec3.y = newValue; } if (this.component == Axis.Z) { vec3.z = newValue; } this.variable.Set(vec3, gameObject); break; } }
// PRIVATE METHODS: ----------------------------------------------------------------------- private bool CanSave() { Variable.DataType type = (Variable.DataType) this.spType.enumValueIndex; return(Variable.CanSave(type)); }
public Item(string name, Variable.DataType type) { this.name = name; this.type = type; }
protected override void Start() { base.Start(); if (!Application.isPlaying) { return; } object current = this.variable.Get(gameObject); if (current != null) { Variable.DataType dataType = this.variable.GetVariableDataType(gameObject); switch (dataType) { case Variable.DataType.Vector2: if (this.component == Axis.X) { this.value = ((Vector2)current).x; } if (this.component == Axis.Y) { this.value = ((Vector2)current).y; } break; case Variable.DataType.Vector3: if (this.component == Axis.X) { this.value = ((Vector3)current).x; } if (this.component == Axis.Y) { this.value = ((Vector3)current).y; } if (this.component == Axis.Z) { this.value = ((Vector3)current).z; } break; } this.onValueChanged.AddListener(this.SyncVariableWithValue); } switch (this.variable.variableType) { case VariableProperty.GetVarType.GlobalVariable: VariablesManager.events.SetOnChangeGlobal( SyncValueWithVariable, this.variable.GetVariableID() ); break; case VariableProperty.GetVarType.LocalVariable: VariablesManager.events.SetOnChangeLocal( SyncValueWithVariable, this.variable.GetLocalVariableGameObject(gameObject), this.variable.GetVariableID() ); break; case VariableProperty.GetVarType.ListVariable: VariablesManager.events.StartListenListAny( SyncValueWithList, this.variable.GetListVariableGameObject(gameObject) ); break; } }